﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Solution.Business.Component;
using Solution.Business.Entities;
using Solution.Data;
using System.Data;

namespace Solution.UI.Web.Controllers.Admin
{
    public class AdminSendMailController : Controller
    {
        private SolutionEntities db = new SolutionEntities();
        //
        // GET: /AdminSendMail/

        public ActionResult Edit(int id = 1)
        {
            MailInfo mail = db.MailInfoes.Find(id);
            if (mail == null)
            {
                return HttpNotFound();
            }
            return View(mail);
        }

        [HttpPost]
        public ActionResult Edit(MailInfo mail)
        {
            if (ModelState.IsValid)
            {
                db.Entry(mail).State = EntityState.Modified;
                if (mail.Mail_Smtp != null && mail.Mail_Port != null && mail.Mail_Noreply != null)
                {
                    db.SaveChanges();
                }
                else
                {
                    ModelState.AddModelError("", "Bạn chưa điền đầy đủ thông tin cần nhập vào ô có dấu *!");
                }
            }
            return View(mail);
        }

    }
}
